package com.talkweb.osmharmony.tileprovider.util;

import com.talkweb.osmharmony.tileprovider.MapTileProviderBase;
import ohos.agp.components.Component;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import ohos.eventhandler.InnerEvent;

public class SimpleInvalidationHandler extends EventHandler {
    private Component mComponent;

    public SimpleInvalidationHandler(Component pComponent) {
        super(EventRunner.getMainEventRunner());
        mComponent = pComponent;
    }

    @Override
    protected void processEvent(InnerEvent event) {
        super.processEvent(event);
        switch (event.eventId) {
            case MapTileProviderBase.MAPTILE_SUCCESS_ID:
                if (mComponent != null)
                    mComponent.invalidate();
                break;
        }
    }

    /**
     * See <a href="https://github.com/osmdroid/osmdroid/issues/390">https://github.com/osmdroid/osmdroid/issues/390</a>
     */
    public void destroy() {
        mComponent = null;
    }
}
